package cn.tedu.micro.demo.demo05;

import cn.tedu.micro.demo.client.RabbitChannelManager;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.io.IOException;
@Slf4j
public class ConsumeNackDemo {
    //通过测试方法
    //声明一个队列 nack-queue
    //绑定一个消费监听 手动确认,同时每个消息都拒绝消费
    @Test
    public void testNackConsme() throws IOException, InterruptedException {
        //1.声明队列
        Channel channel = RabbitChannelManager.newChannel();
        channel.queueDeclare(
                "nack-queue",
                false,
                false,
                false,
                null);
        //2.绑定监听消费者
        channel.basicConsume("nack-queue",false,
                (consumerTag,message)->{
                    //消费入口
                    log.info("消息达到消费者");
                    //手动确认 requeue: 是否允许重新入队
                    channel.basicNack(
                            message.getEnvelope().getDeliveryTag(),
                            false,
                            false);
                },
                consumerTag->{
                    //TODO 取消消费的回调
                });
        Thread.sleep(10000000);
    }
}
